package util;

import java.util.List;

public abstract class BitSet {
	private long[] words;
	
	public BitSet() {
		words = new long[maxSize()];
		for (int word : wordList()) {
			add(word);
		}
	}
	
	public abstract int maxSize();
	public abstract List<Integer> wordList();
	
	private int wordIndex(int bitIndex) {
		return bitIndex >> 6;
	}
	
	public void add(int bitIndex) {
		if (bitIndex < 0) {
			return;
		}
		
		int wordIndex = wordIndex(bitIndex);
		if (wordIndex < words.length)
			words[wordIndex] |= 1L << bitIndex; 
	}
	
	public boolean isExist(int bitIndex) {
		if (bitIndex < 0) {
			return false;
		}
		
		int wordIndex = wordIndex(bitIndex);
		return wordIndex < words.length && (words[wordIndex] & (1L << bitIndex)) != 0; 
	}
}
